package me.luger.core.commom.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * PropertyUtil
 *
 * @author luger
 * @date 2016/8/1 0001
 */
public class PropertiesUtil {
    private static String DEF_ENCODING = "UTF-8";
    private static Properties properties = null;

    public static Properties readProperties(String file){
        return readProperties(file,DEF_ENCODING);
    }

    private static Properties readProperties(String fileName, String encoding) {
        InputStream inputStream = null;

        try {
            inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
            if(inputStream == null) {
                throw new IllegalArgumentException("Properties file not found in classpath: " + fileName);
            }

            properties = new Properties();
            properties.load(new InputStreamReader(inputStream, encoding));
        } catch (IOException var12) {
            throw new RuntimeException("Error loading properties file.", var12);
        } finally {
            if(inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    LogUtil.errorLog(e,"");
                }
            }

        }
        return properties;
    }
}
